package org.hyh.javaConfig;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;


/**
 * @auther :hyh
 * @desc :
 * @date :2019/12/12
 */
@Service
public class AUser   implements BeanPostProcessor, ApplicationContextAware {

	ApplicationContext applicationContext;

	@Value("${AA}")
	private  String  aa;


	@Autowired
	private AStudent student;

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if (bean instanceof AUser && ((AUser) bean).student != null) {
			((AUser) bean).student.setName("我是擦徐坤");
		}
		return bean;
	}

	@Autowired
	private ATeacher aTeacher;


	public AStudent getStudent() {
		return student;
	}

	public void setStudent(AStudent student) {
		this.student = student;
	}

	public ATeacher getaTeacher() {
		return aTeacher;
	}

	public void setaTeacher(ATeacher aTeacher) {
		this.aTeacher = aTeacher;
	}


	@Override
	public String toString() {
		return "AUser{" +
				"applicationContext=" + applicationContext +
				", aa='" + aa + '\'' +
				", student=" + student +
				", aTeacher=" + aTeacher +
				'}';
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		AStudent bean = applicationContext.getBean(this.student.getClass());
		bean.setName("奥力给");

	}


}
